Ext.define('DCApp.view.article.DetailController', {
    extend: 'DCApp.controller.DetailController',
    alias: 'controller.Articledetail',

    onPreview: function() {
    	var rec = this.getViewModel().get('theObj');
    	Ext.Ajax.request({
		   method : 'GET',
		   url : '/article_uri/'+rec.get('id'),
           success: function(result, request) {
        	   var obj = Ext.decode(result.responseText);
        	   var secs = rec.get('postto');
        	   //open window for one page
        	   if(obj.length==1){
            	   new Ext.Window({
            		modal:true,
            		maximizable:true,
           		    title : '<a target="preview" href="'+ obj[0]+'" >'+(secs||'默认发布')+'</a>',
           		    width : 800,
           		    height: 600,
           		    layout : 'fit',
           		    items : [{
           		        xtype : "component",
           		        autoEl : {
           		            tag : "iframe",
           		            src : obj[0]
           		        }
           		    }]
           		}).show();
        	   } //open tab window for multipage
        	   else{
        		   var its=[];
        		   var tis = secs.split(';');
        		   var len = Math.min(obj.length, tis.length);
        		   for(var i=0; i< len; i++){
        			   its[its.length]={
             	            title: '<a target="preview" href="'+ obj[i]+'" >'+ tis[i] +'</a>',
                	        xtype : "component",
               		        autoEl : {
               		            tag : "iframe",
               		            src : obj[i]
               		        }
                	  };
        		   }
            	   new Ext.Window({
               		modal:true,
               		maximizable:true,
               		title : "发布预览",
              		width : 800,
              		height: 600,
              		layout: 'fit',
              	    items: {
              	        xtype: 'tabpanel',
              	        items: its
              	    }
              		}).show();
        		   
        	   }
           }
    	});
    }
});
